import logging
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from sqlalchemy.ext.declarative import declarative_base

# 数据库连接配置
SQLALCHEMY_DATABASE_URI = "mysql+pymysql://root:wxt200413@localhost/fuchuangweb?charset=utf8mb4"  # 用户:密码@服务器/数据库

logger = logging.getLogger(__name__)

# 创建数据库引擎
engine = create_engine(SQLALCHEMY_DATABASE_URI)
# 创建数据库会话
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
# 声明基类
Base = declarative_base()

# 检查数据库连接是否成功
try:
    conn = engine.connect()
    conn.close()
    logger.info("Database connection successful")
except Exception as e:
    logger.error("Unable to connect to the database: %s", str(e))
